package com.onec.service.queue;

import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.PriorityBlockingQueue;

/**
 * 双端队列
 */
public class PollTask implements Runnable {

    // 非阻塞安全双端队列
    private final ConcurrentLinkedDeque<String> queue;
    // 阻塞安全双端队列
    private final LinkedBlockingDeque<String> stringLinkedBlockingDeque;
    // 优先级排序的阻塞安全队列  排序 实现compareTo 接口
    private final PriorityBlockingQueue<String> priorityBlockingQueue;

    //
    private  final ConcurrentSkipListMap concurrentSkipListMap;

    public PollTask(ConcurrentLinkedDeque<String> queue, ConcurrentSkipListMap concurrentSkipListMap) {
        this.queue = queue;
        this.concurrentSkipListMap = concurrentSkipListMap;
        stringLinkedBlockingDeque = new LinkedBlockingDeque<>();
        priorityBlockingQueue = new PriorityBlockingQueue<>();
    }


    @Override
    public void run() {
        for (int i = 0; i < 5000; i++) {
            queue.pollFirst();
            queue.pollLast();

            // 获取不删除
            queue.getFirst();
            queue.getLast();
        }
    }
}
